package com.zmn.plat.admin.controller.plat.contract.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.common.dictionary.DictModel;
import com.zmn.plat.manager.dictionary.ProductDict;
import com.zmn.plat.model.entity.plat.contract.model.PlatContractModel;
import com.zmn.plat.model.entity.plat.contract.model.PlatContractModelQuery;
import com.zmn.plat.model.entity.plat.contract.model.log.PlatContractModelLog;
import com.zmn.plat.model.entity.plat.contract.model.log.PlatContractModelLogQuery;

/**
 * 平台服务合同模式
 *
 * @author linfeng
 *
 * @since 2020/09/18 18:23
 */
@Controller
@RequestMapping("/plat/contract/model/")
public class PlatContractModelListController extends PlatContractModelBaseController {

    /**
     * 平台服务合同模式详情
     * 
     * @author linfeng
     * @param query
     * @since 2020/09/18 18:22
     */
    @RequestMapping("detail")
    @RequiresPermissions("/plat/contract/model/detail.action")
    public ModelAndView detail(@ModelAttribute PlatContractModelQuery query) {

        List<PlatContractModel> platBizTypes = platContractModelService.listAll();
        Map<Integer, PlatContractModel> map = platBizTypes.stream().collect(Collectors.toMap(o -> o.getPlat(), o -> o));
        List<DictModel> plats = ProductDict.getPlatList();

        List<PlatContractModelLog> logList = new ArrayList<>();
        PlatContractModelLogQuery logQuery = new PlatContractModelLogQuery();
        logQuery.setPageIndex(0);
        logQuery.setPageSize(50);
        logList = platContractModelLogService.listPageByQuery(logQuery);

        ModelAndView mav = new ModelAndView("plat/contract/model/detail");
        mav.addObject("map", map);
        mav.addObject("items", logList);
        mav.addObject("plats", plats);
        mav.addObject("contractModelList", com.zmn.plat.common.dictionary.PlatContractModelDict.listPlatContractModel());

        return mav;
    }
}
